<?php
namespace app\admin\controller;
/**
* 商户配置
*/
class Shcon extends Common
{
	// 配置列表
	public function member_list(){
		$sel = db('conf')->select();
		$this->assign('mchid',$sel);
		return view();

	}
	// 添加页面
	public function member_add(){

		$merchant=db('merchant')->field("name,id")->select();
		$this->assign('merchant',$merchant);
		if(!empty($_POST)){
          $user = db('conf')->where("mid = ".$_POST['user']."")->find();
           echo json_encode($user);
           exit ;
		}

		

		return view();
	}
	// 添加
	public function medber_add_ad(){

		if($_POST['typesy'] == 1){ //配置微信
		//	$data = input('post.');
           $data = array(
			'appid' => input('post.appid'),
			'appSecret' => input('post.appSecret'),
			'mchId' => input('post.mchId'),
			'key' => input('post.key'),
			'body' => input('post.body'),
			'zf_title' => input('post.zf_title'),
			'beizhu' => input('post.beizhu'),
			'mid' => input('post.mid'),
		  );
            $add = db('conf');
		}else if($_POST['typesy'] == 2){
			$add = db('zfb');
			// echo "支付宝";
			echo '失败';
		}

		$sel = $add->where("mid = ".$_POST['mid']."")->field("id,mchId,mid")->find();
		if(!empty($sel)){
          $mid = $add->where("mid = ".$_POST['mid']."")->update($data);
          if($mid == 1){
              echo 0;
              exit ;
          }else{
          	  echo 1;
          	  exit ;
          }
		}else{
		  $ad = $add->insert($data);
		  if($ad == 1){
		  	echo 2;
		  	exit ;
		  }else{
            echo 3;
            exit ;
		  }
		}

		
	}

	public function system_base(){
		return view();
	}
}
